<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class GameStatus extends Model
{
    public $timestamps = false;
    protected $table = 'base_game_status';


    /**
     * 修改
     * @param $gameStatus
     * @param $request
     * @return array
     */
    static function GameStatusModify($gameStatus, $request)
    {
        foreach (['name', 'min_energy', 'max_energy', 'img_url', 'discount'] as $item) {
            $gameStatus->$item = $request->$item;
        }
        if (!$gameStatus->save()) {
            return ['status' => 2, 'message' => '修改失败'];
        }
        return ['status' => 1, 'message' => '修改成功'];
    }

    static function GameStatusPublish($game_id, $request)
    {
        $gameStatus = new GameStatus();
        $gameStatus->game_id = $game_id;
        foreach (['name', 'min_energy', 'max_energy', 'img_url', 'discount'] as $item) {
            $gameStatus->$item = $request->$item;
        }
        if (!$gameStatus->save()) {
            return ['status' => 2, 'message' => '添加失败'];
        }
        return ['status' => 1, 'message' => '添加成功'];
    }
}
